'use strict';

const { DataTypes } = require('sequelize');
const sequelize = require('../../database/sequelize');

const Wishlist = sequelize.define(
  'Wishlist',
  {
    id: {
      type: DataTypes.INTEGER.UNSIGNED,
      primaryKey: true,
      autoIncrement: true,
      comment: '主键ID',
    },
    user_id: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      comment: '用户ID',
    },
    city_id: {
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      comment: '城市ID',
    },
  },
  {
    tableName: 'wishlists',
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at',
    underscored: true,
    indexes: [
      {
        unique: true,
        fields: ['user_id', 'city_id'],
        name: 'uniq_user_city',
      },
    ],
  }
);

// 同步模型到数据库（开发环境）
// Wishlist.sync({ alter: true });

module.exports = Wishlist;